import {
    ChartActionType,
    ICtrlDataAction,
    ICtrlEvent,
    IChartAbility,
    IChartControllerParams,
    IChartModel,
    IChartStore,
    IParam,
    IChartController,
} from '@/core';
import { QXEvent } from 'qx-util';
import { PropType } from 'vue';
import {
    getCtrlClassNames,
    useCtrlAction,
    useCtrlBasic,
    useCtrlControllerParams,
    useCtrlProps,
} from '../use-ctrl';

/**
 * 图表输入参数
 *
 * @export
 * @return {*}
 */
export function useChartProps() {
    return {
        ...useCtrlProps(),
        openView: Function,
        newView: Function,
        actions: Object as PropType<ICtrlDataAction>,
        selectFirstDefault: Boolean,
    };
}

/**
 * 图表基础参数
 *
 * @export
 * @param {IChartModel} model
 * @param {IParam} props
 * @return {*}
 */
export function useChartBasic(model: IChartModel, props: IParam) {
    const getClassNames = (props: IParam) => {
        const names = getCtrlClassNames(model, props);
        return names;
    };
    return {
        ...useCtrlBasic(model, props),
        getClassNames,
    };
}

/**
 * 图表部件行为
 *
 * @export
 */
export function useChartAction(controller: IChartController<IChartStore,IChartAbility>) {
    return {
        ...useCtrlAction(controller),
    };
}

/**
 * 图表部件控制器
 *
 * @export
 */
export function useChartControllerParams<
    S extends IChartStore,
    M extends IChartModel
>(
    model: M,
    props: any,
    evt: QXEvent<ICtrlEvent<ChartActionType, IChartAbility>>,
    otherParams: IParam = {},
): IChartControllerParams<ChartActionType, IChartAbility> {
    return {
        ...useCtrlControllerParams<S, M>(model, props, evt, otherParams),
        actions: props.actions,
        selectFirstDefault: props.selectFirstDefault,
        openView: props.openView,
        newView: props.newView,
    };
}
